package pers.qianyu.comment.controller;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;
import pers.qianyu.core.http.*;
import pers.qianyu.comment.pojo.dto.*;
import pers.qianyu.comment.pojo.vo.*;
import pers.qianyu.comment.service.*;

import java.util.*;

@RestController
@Api("与评论相关的api接口")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/comment/{id}")
    @ApiOperation("根据评论的 id 查询评论列表")
    public HttpResult<CommentVO> getCommentById(@PathVariable(value = "id") Long id) {
        CommentVO commentVO = commentService.findById(id);
        return HttpResult.ok(commentVO);
    }

    @GetMapping("/comments/{id}")
    @ApiOperation("根据评论对象 id 查询评论信息")
    public HttpResult<List<CommentVO>> getCommentByTopicId(@PathVariable(value = "id") Long topicId) {
        List<CommentVO> comments = commentService.findCommentsByTopicId(topicId);
        return HttpResult.ok(comments);
    }

    @PostMapping("/comment")
    @ApiOperation("新增评论")
    public HttpResult<?> comment(@RequestBody CommentDTO commentDTO) {
        commentService.insertComment(commentDTO);
        return HttpResult.ok().setMessage("评论插入成功");
    }
}
